/**
 * Created by edwin on 2017/5/20.
 */
const Vue = require('vue');
const server = require('express')();
const renderer = require('vue-server-renderer').createRenderer();

const context = {
    title: 'hello11',
    meta: `
    <meta ...>
    <meta ...>
  `
}

server.get('*',(req,res)=>{
    const app = new Vue({
        data:{
            url:req.url
        },
        template:`<div>The visited URL is :{{ url }}</div>`
    });

    renderer.renderToString(app,context,(err,html)=>{
        if(err){
            res.status(500).end('Internal server Error');
            return;
        };

        res.end(`
        <!DOCTYPE html>
        <html lang='en'>
            <head><title>${context.title}</title></head>
            <body>${html}</body>
        </html>
        `);
    });
});
server.listen(8080);